using System;
using System.Net.Mail;
using System.Text;
using System.Xml;

namespace SpiderMaster.AspNet.TradingSystem
{
    public partial class EmailManagerOld
    {
        internal partial class Reader
        {
            internal static void LoadContactUs(MailMessage EmailMessage, String UserName, string FirstName, Int32 ToMemberId, String Subject, String Details, string EmailAddress, String Administrator)
            {
                //load email body form xml file and set the constant values from xml 
                XmlDocument doc = new XmlDocument();
                doc.Load(AppDomain.CurrentDomain.BaseDirectory + @"\App_Data\Email\Body\ContactUsEmail.xml");

                XmlElement el = doc.DocumentElement;
                XmlNode nodeSubject = el.ChildNodes[0].ChildNodes[0];
                XmlNode nodeBody = el.ChildNodes[1].ChildNodes[0];
                XmlNode nodefrom = el.ChildNodes[2].ChildNodes[0];
                XmlNode nodedisplay = el.ChildNodes[3].ChildNodes[0];
                XmlNode nodebcc = el.ChildNodes[4].ChildNodes[0];

                EmailMessage.Subject = nodeSubject.Value;
                EmailMessage.From = new MailAddress(nodefrom.Value, nodedisplay.Value);
                EmailMessage.To.Clear();
                EmailMessage.To.Add(EmailAddress);

                string[] bccList = nodebcc.Value.Split(new char[] { ';' });
                EmailMessage.Bcc.Clear();
                foreach (string bccstr in bccList)
                    EmailMessage.Bcc.Add(bccstr);

                StringBuilder body = new StringBuilder();
                body.Append("<html> <head> </head> <body> <p>");
                string EmailBody = nodeBody.Value;

                EmailBody = EmailBody.Replace("$HeaderImage$", LinkLoader.Cache.CommonHeaderImage());
                EmailBody = EmailBody.Replace("$Subject$", Subject);
                EmailBody = EmailBody.Replace("$Administrator$", Administrator);
                EmailBody = EmailBody.Replace("$FirstName$", FirstName);
                EmailBody = EmailBody.Replace("$Details$", Details);
                EmailBody = EmailBody.Replace("$MemberId$", ToMemberId.ToString());
                EmailBody = EmailBody.Replace("$UserName$", UserName);
                body.Append(EmailBody);
                body.Append("</p> </body></html>");

                EmailMessage.Body = body.ToString();
            }
        }
    }
}